const http = uni.$u.http

// 根据代理商信息获取可用的电站类型
export function getStationTypes() {
	return http.get('/api/options/plantType');
}

export function getAgentAddress(params) {
	return http.get(`/api/options/agentAdress`, {
		params
	});
}

export function getAllAddress(params) {
	return http.get(`/api/options/getAllAdress`, {
		params
	});
}
/**
 * 根据type 获取字典
 * CERTTYPE(1, "证件类型"),                  COUNTRY(2, "证件国别"),                  CUSTOMERNATURE(3, "客户性质"),             GENDER(4, "客户性别"),             NATION(5, "民族"),
   MARITAL(6, "婚姻状况"),                   EDUCAT(7, "最高学位"),                   EDUCATIONLEVEL(8, "最高学历"),             WORKAS(9, "职业分类"),             JOBTITLE(10, "职称"),
   POSITION(11, "职务"),                     INDUSTRY(12, "所属行业"),                EMPLOYMENTSITUATION(13, "就业状况"),       WORKYEARS(14, "在职年限"),         PRIMARYINCOME(15, "主要收入来源"),
   HOUSENATURE(16, "房屋性质"),              AGELIMIT(17, "现居住地居住年限"),         CUSTRELATION(18, "共签人与承租人关系"),    CUSTENTERPRISETYPE(19, "企业类型"),ENTERPRISEECONOMICTYPE(20, "经济类型"),
   TAXQUALIFICATION(21, "税务资质"),         COMPANYTYPE(22, "企业性质"),             ENTERPRISESCALE(23, "企业规模"),           STAFFSIZE(24, "员工规模"),         SPONSORIDENTIFYTYPE(25, "出资人身份类别"),
   INVESTORCERTTYPE(26, "出资人身份标识类型"),SPONSORTYPE(27, "出资人类型"),           QUERYRESULT(28, "合同状态"),               VERSTATUS(29, "核销状态"),         SCHEDULETYPE(30, "款项类型"),             
   SETTLETYPE(31, "结清类型"),               RESOLUTIONTYPE(32, "决议类型"),          HEADERBANKNAME(33, "开户行全称"),          YESNO(34, "是否")
 */
export function getDict(type, plantType) {
	return http.get(`/api/options/getDicts?type=${type}&plantType=${plantType}`)
}
/**
 * 发起个性协议
 * @param {
	 area:区县id
	 plantType:电站类型
	 custName:用户姓名
	 mobilePhone:用户手机号
	 certId:用户身份证
	 commonSign:{
	   certId: 共签人身份证
	   custName:共签人姓名
	   mobilePhone:共签人手机号
	 }
 }
 */
export function PersonalAgreement(params) {
	return http.post('/api/peasant/personalAgreement', params)
}
/**
 * 重发个性签署短信
 * @param {
 * 	contractId
 * } 
 */
export function ReSendSMS(params) {
	return http.get('/api/sign/reSend', {
		params
	})
}
export function getStationList(params) {
	let timeParams = '';
	if (params?.params?.beginTime) {
		timeParams += `?params[beginTime]=${encodeURIComponent(params.params.beginTime)}`
	}
	if (params?.params?.endTime) {
		timeParams += params.params.beginTime ? '&' : '?'
		timeParams += `params[endTime]=${encodeURIComponent(params.params.endTime)}`
	}
	if (timeParams) {
		timeParams = encodeURI(timeParams);
	}

	return http.get(`/api/peasant/list${timeParams}`, {
		params: {
			...params,
			params: null
		}
	});
}

export function getStationListForDevice(params) {
	return http.get(`/stationGuest/getByCodeOrGuest`, {
		params: {
			...params,
		}
	});
}

export function updateStationDevice(data, showToast = true) {
	return http.post(`/stationGuest/updateTemplate`, data, {
		custom: {
			showToast
		}
	});
}


export function uploadFile(filePath) {
	return http.upload('/api/storage', {
		name: 'file',
		filePath,
		formData: {
			root: 'PUBLIC',
			thumbnail: true
		}
	})
}

export function mergeIdcard(front, back) {
	return http.get('/api/storage/merge', {
		params: {
			back,
			front,
		}
	})
}

export function ocrIdCard(url, front) {
	return http.post('/api/storage/idcard', {
		url,
		front,
	})
}

export function saveStation(data) {
	return http.post('/api/peasant', data);
}

export function getStationDetail(id) {
	return http.get(`/api/peasant/${id}`);
}

export function updateStation(data) {
	return http.request({
		url: `${http.config.baseURL}/api/peasant`,
		method: 'PUT',
		data
	});
}

export function submitStation(data) {
	return http.request({
		url: `${http.config.baseURL}/api/peasant/commit`,
		method: 'PUT',
		data
	});
}
/**
 * data: {
	 id,
	 isCommonSign: '0'不是共签人
 }
 */
export function sendVerify(data) {
	return http.post('/api/peasant/messageVerify', data);
}

export function getCertificateDownload(data) {
	return http.request({
		url: '/api/PropertyCertificate/getDownloadUrl',
		method: 'POST',
		data
	});
}

export function getCertificateProperty(orderId) {
	return http.get('/api/PropertyCertificate/getPropertyCertificate', {
		params: {
			orderid: orderId
		}
	})
}

/**
 * 越秀-查询预审结果
 * @param {
* 	id: 电站id
* }
*/
export function GetPreCheckResult(id) {
	return http.get(`/api/financial/letters/info/${id}`);
}
/**
* 获取开卡链接
* @param {
*  id: 电站id
* }
*/
export function GetOpenCardUrl(id) {
	return http.get(`/api/financial/openBlock/${id}`);
}
/**
 * 获取可选应用场景
 * @param {
 *   provinceid: 省份id，
 *   cityid: 城市id，
 *   areaid: 区县id，
 *   stationtype: 电站类型
 * }
 */
export function GetApplicationScenes(params) {
	return http.get('/api/peasant/scenario', {
		params
	});
}
/**
 * 查询可选银行名称列表
 * @param {
 *   bankFullName,
 *   pageSize,
 *   pageNum
 * }
 */
export function GetBankNameList(params) {
	return http.get('/api/bankBranch/list', {
		params
	});
}

// 删除商机
export function removePeasant(id) {
	return http.delete(`/api/peasant/remove/${id}`);
}